package com.example.werewolf.utils;

import com.example.werewolf.entity.Player;
import com.example.werewolf.model.sse.MessageRecord;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;
import java.time.LocalDateTime;

public class PrintUtils {

    public static void printPlayer(SseEmitter emitter, Player player, String content) {
        try {
            emitter.send(SseEmitter.event()
                    .data(MessageRecord.builder()
                            .id(String.valueOf(player.getId()))
                            .text(content)
                            .time(LocalDateTime.now().toString())
                            .type("msg")
                            .build())
            );
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }



    public static void printSystem(SseEmitter emitter, String content) {
        try {
            emitter.send(SseEmitter.event().data(
                    MessageRecord.builder()
                            .text(content)
                            .time(LocalDateTime.now().toString())
                            .type("phase")
                            .build()));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
